package com.cps116.friendstracker;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class UserLocationUpdateService extends Service {

	private float userUpdateTimePreference;
	private static final float DEFAULT_UPDATE_TIME = 1000000000;
	private UserLocationUpdater updater;
	
	public UserLocationUpdateService()
	{
		updater = new UserLocationUpdater(DEFAULT_UPDATE_TIME);
	}
	
	
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		 super.onStartCommand(intent, flags, startId);
		
		 updater.start();
		 return START_STICKY;
	}


	
	public void setUpdateTime(float seconds)
	{
		if(seconds != userUpdateTimePreference)
		{
			userUpdateTimePreference = seconds;
			updater.interrupt();
			
			//need to kill all existing UserLocationUpdater thread
			//then run the current thread with the second preference
		}
	}
	

	
	private class UserLocationUpdater extends Thread {

		private float delay = 0;
		
		public UserLocationUpdater(float delay)
		{
			this.delay = delay;
		}
		
		
		@Override
		public void run() {
			super.run();
			
			
			
			
			
			
			
		}

		@Override
		public synchronized void start() {
			super.start();
		}

		@Override
		public void destroy() {
			super.destroy();
		}
	}
	
	
	
	
	
}
